<template>
    <div>

        <div style="margin: 10px 0">
            <el-input style="width: 250px" placeholder="农物名称" suffix-icon="el-icon-search" class="ml-5" v-model="agriculture"></el-input>
            <el-input style="width: 250px" placeholder="产品种类" suffix-icon="el-icon-edit" class="ml-5" v-model="variety"></el-input>
            <el-button class="ml-5" type="primary" @click="load">搜索</el-button>
            <el-button class="ml-5" type="warning" @click="reset">重置</el-button>
        </div>


        <el-table :data="tableData" border stripe :header-row-class-name="headerBg" @selection-change="handleSelectionChange">  //border stripe把表格变成斑马线风格
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="id" label="ID" width="70"></el-table-column>
            <el-table-column prop="agriculture" label="农物名称" width="120"></el-table-column>
            <el-table-column prop="variety" label="归属品种" width="100"></el-table-column>
            <el-table-column prop="message" label="短信审核通知内容" width="250"></el-table-column>
            <el-table-column align="center" label="操作">
                <template slot-scope="scope">
                    <el-popconfirm
                            class="ml-5"
                            confirm-button-text='确定'
                            cancel-button-text='取消'
                            icon="el-icon-info"
                            icon-color="red"
                            title="确定删除吗？"
                            @confirm="del(scope.row.id)"
                    >
                        <el-button type="danger" slot="reference">删除</el-button>
                    </el-popconfirm>
                    <!--<el-button  type="warning" @click="details(scope.row)">查看详情</el-button>-->

                </template>
            </el-table-column>
        </el-table>
        <div style="padding: 10px 0">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="pageSize"
                    :page-sizes="[5, 10, 15, 20]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>

    </div>
</template>

<script>
    export default {
        name: "Message",
        data(){
            return{
                tableData: [],
                total: 0,
                pageNum: 1,   //点进来默认的页数和条数
                pageSize: 5,
                Id: '',
                message: '',
                beMessage: '',
                agriculture: '',
                variety: '',
                creatTime:'',
                beMessager: '',
                form: {
                    Id: '',
                    message: '',
                    beMessage: '',
                    agriculture: '',
                    variety: '',
                    creatTime:'',
                    beMessager: ''
                },
                dialogFormVisible: false,
                multipleSelection: [],
                headerBg: "headerBg",
                dialogVisible: false,

            }

        },
        created() {
            //请求分页查询数据
            this.load();
        },
        methods: {
            load() {     //封装请求分页查询方法，让其他地方调用
                this.request.get("/message/list", {
                    params: {   //筛选条件
                        pageNum: this.pageNum,
                        pageSize: this.pageSize,
                        beMessager: localStorage.getItem("userName"),
                        agriculture: this.agriculture,
                        variety: this.variety,
                    }
                }).then(res => {
                    console.log(res)
                    this.tableData = res.data.rows
                    this.total = res.data.total
                })
            },
            del(id){
                this.request.post("/message/delete",id).then(res=>{
                    if (res){
                        this.$message.success("删除成功")
                        this.load()
                    }else {
                        this.$message.fail("删除失败")
                    }
                })
            },
            handleInputOpenValue(e) {
                this.$forceUpdate();
            },
            handleAdd() {   //新增打开表单默认为空
                this.dialogFormVisible = true
                this.form = {}
            },
            handleEdit(row) {   //编辑打开为form里面的数据
                console.log(row)
                this.form = row
                this.dialogFormVisible = true
            },
            reset() {  //重置
                this.agriculture = ""
                this.variety = ""
                this.load()
            },

            handleSelectionChange(val) {

                this.multipleSelection = val
                console.log(val)
            },
            handleSizeChange(pageSize) {     //点击触发分页跳转,pageSize是web点击后传过来的
                console.log(pageSize)
                this.pageSize = pageSize
                this.load()
            },
            handleCurrentChange(pageNum) {
                console.log(pageNum)
                this.pageNum = pageNum
                this.load()
            },
            details(row) {
                this.dialogVisible = true
                this.form = row
            }
        }
    }

</script>

<style>
    .headerBg{
        background: #cccccc !important;
    }
</style>
